package CommonEvent;

import io.appium.java_client.TouchAction;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.touch.offset.PointOption;

import static Utils.MyLogger.logInfo;

/**
 * @author 锄禾
 * @projectName MkPack
 * @description: Monkey输入操作事件
 */
public class MonkeySubEvent extends MonkeyEvent{
    private AndroidDriver androidDriver;
    private int x;
    private int y;

    public MonkeySubEvent(AndroidDriver driver,int x, int y){
        super(MonkeyEvent.EVENT_TYPE_SUBMIT);
        this.x = x;
        this.y = y;
        androidDriver = driver;
    }

    public int injectEvent(){
        try {
            logInfo("随机输入事件:点击-->(" + x + ", " + y + ")");
            TouchAction touchAction = new TouchAction(androidDriver);
            touchAction.tap(PointOption.point(x,y)).perform();
            return MonkeyEvent.INJECT_SUCCESS;
        } catch (Exception e) {
            //e.printStackTrace();
            logInfo(this.getClass().getName() + "-" + "随机输入事件异常：" + e);
            return MonkeyEvent.INJECT_FIAL;
        }
    }
}
